import React from "react"

import http from "@/api/helper/request"

import { IAuditRecordParams, IQueryItemDetailParams, IQueryListParams, IResponseItem, IResponseItemDetail } from "./types"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const list = (body?: IQueryListParams) =>
		generalHttp<Business.TableResourceType<IResponseItem>>("/UpTopProxyAudit/auditList", body)

	const detail = (body?: IQueryItemDetailParams) => generalHttp<IResponseItemDetail>("/UpTopProxyAudit/queryAuditDetail", body)

	const lockChange = (body?: any) => generalHttp("UpTopProxyAudit/auditLock", body)

	const auditRecord = (body?: IAuditRecordParams) => generalHttp("/UpTopProxyAudit/audit", body)

	return {
		loading,
		generalHttp,
		list,
		detail,
		lockChange,
		auditRecord
	}
}

export default useApi
